home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / text / edit / Smartindent.lha / Smartindent / Source / util.h < prev    next >
C/C++ Source or Header  |  1997-12-14  |  4KB  |  159 lines

  1. /*(( "Kopf" */
  2. /* -----------------------------------------------------------------------------
  3.  
  4.    $Id: util.h,v 1.4 1997/06/29 19:24:13 mshopf Exp mshopf $
  5.  
  6.    GoldED API client, ©1997 Matthias Hopf.
  7.    Compiled with SasC.
  8.  
  9.  
  10.    Utility functions.
  11.  
  12.    ------------------------------------------------------------------------------
  13. */
  14.  
  15. /*)) */
  16. #ifndef _UTIL_H
  17. #define _UTIL_H
  18.  
  19. /*(( "Includes" */
  20.  
  21. #include "smartindent.h"
  22.  
  23. #include <proto/exec.h>
  24.  
  25. #include <stdio.h>
  26. #include <ctype.h>
  27. #include <string.h>
  28.  
  29. /*)) */
  30. /*(( "Constants" */
  31.  
  32. #define MODE_LINE     1
  33. #define MODE_LASTLINE 2
  34. #define MODE_BLOCK    4
  35. #define MODE_CURSOR   8
  36.  
  37. #define ADD_SPARSE_INDENTATION 8    /* Allocate more memory than needed for future same line intendations */
  38.  
  39. /*)) */
  40. /*(( "Data" */
  41.  
  42. extern struct Conf      Config;
  43. extern struct Semantic *Semantics[];
  44.  
  45. extern int ExecVersion;
  46. extern int MemAllocSmallFlags;
  47.  
  48.  
  49. /*)) */
  50. /*(( "Common Errors" */
  51.  
  52. /* Errors that are not specific to a semantic parser */
  53.  
  54. extern const char *SYNTAX_ERROR;
  55. extern const char *UNMATCHED_BRACE_ERROR;
  56. extern const char *PRAEPROCESSOR_ERROR;
  57. extern const char *SUSPICIOUS_ERROR;
  58. extern const char *STRING_TERMINATION_ERROR;
  59. extern const char *INTERNAL_ERROR;
  60.  
  61. /* Errors that are not parser related */
  62.  
  63. extern const char *UNKNOWN_MODE_ERROR;
  64. extern const char *UNSPECIFIED_MODE_ERROR;
  65.  
  66. /*))*/
  67.  
  68.  
  69. // Comment this out if you don't want debugging enabled
  70. #define DEBUG 1
  71. /*(( "Debugging" */
  72.  
  73. #ifdef DEBUG
  74. extern  int Dbug;
  75. #define D_WORD     1
  76. #define D_MOVE     2
  77. #define D_ERROR    4
  78. #define D_PARSER   8
  79. #define D_RETURN   16
  80. #define D_KEY      32
  81. #define D_CURSOR   64
  82. #define D_REQUESTS 128
  83.  
  84. #define debug(a,b)    do { if (Dbug & a) Printf b; } while (0)
  85. #else
  86. #define debug(a,b)    ((void)0)
  87. #define dcheck        ((void)0)
  88. #endif
  89.  
  90. /*)) */
  91. /*(( "Macros" */
  92.  
  93. #define offsetof(s,c)  (((char *)&((s *)0)->c) - (char *)0)
  94. #define OrderString(o) ((char *)((o)+1))
  95. #define streq(a,b)     (strcmp ((a), (b)) == 0)
  96.  
  97. /**** still to be done better (remove sprintf() here) */
  98. #define Error(c,e)     do { if (! (c)->ErrTxt) { c->ErrTxt = c->ErrBuffer; sprintf (c->ErrBuffer, e, c->CurrentLine+1); } debug (D_ERROR, ("***%s on line/pos %ld/%ld*** \t", e, c->CurrentLine, c->CurrentPos)); } while (0)
  99. #define ErrRet(c,e)    do { Error (c, e); return; } while (0)
  100.  
  101. /*)) */
  102.  
  103. /*(( "Prototypes" */
  104.  
  105. /*
  106.  * Only process lines in increasing line number order!
  107.  * Otherwise neat effects may happen as the system only
  108.  * keeps track of the last modfied line and does not
  109.  * scan all ModifyRequest that are already done.
  110.  */
  111.  
  112. /*
  113.  * Initialize.
  114.  */
  115. void InitIndent (sc_t *c, int BeginLine, int EndLine, int Mode);
  116.  
  117. /*
  118.  * Cleanup and add any remaining APIOrders.
  119.  */
  120. void CleanupIndent (sc_t *c);
  121.  
  122. /*
  123.  * Free the APIOrder, APIModifyRequest and the string space.
  124.  */
  125. void FreeRequest (sc_t *c, struct SmartOrder *Req);
  126.  
  127. /*
  128.  * Get *real* current line text and length.
  129.  */
  130.  
  131. void GetText (sc_t *c, char **Text, int *Len);
  132.  
  133. /*
  134.  * Move current line contents at position Pos when indentation is enabled
  135.  * for the current line.
  136.  * Perform indentation correctness checks.
  137.  */
  138. void Move (sc_t *c, int Pos, int NewPos);
  139.  
  140. /*
  141.  * Get the next word (maximum length MAX_WORD_LEN-1).
  142.  * Returns an empty word after EOF.
  143.  * Sets Current* when Flag is set.
  144.  */
  145. void NextWord (sc_t *c, char *buf, int Flag);
  146.  
  147. /*
  148.  * Unget the current word.
  149.  * CurrentPos will not point to the very correct Place, but it will be a good
  150.  * guess nevertheless. At least it still works for BeginOfLine determination
  151.  * after the next GET. LastPos will not be correct at all.
  152.  */
  153. void LastWord (sc_t *c);
  154.  
  155. /*)) */
  156.  
  157. #endif /* _UTIL_H_ */
  158.  
  159.